1089G - Guest Student - CodeForces Solution


math *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
// 	cout<<"GfG!";
    int t;
    cin>>t;
    while(t--)
    {
        ll int k;
        cin>>k;
        
        vector<ll int> v1;
        for(ll int i=0; i<7; i++)
        {
            ll int x;
            cin>>x;
            v1.push_back(x);
        }
        
        for(ll int i=0; i<14; i++)
        {
            v1.push_back(v1[i]);
        }
        
        // for(ll int i=0; i<21; i++)
        // {
        //     cout<<v1[i];
        // }
        
        ll int b,l,d;
        ll int ans,ans1;
        ans1=1e9+10;
        for(ll int i=0; i<7; i++)
        {
            d=0;
            for(ll int j=0; j<7; j++)
            {
                if(v1[i+j]==1)
                {
                    d++;
                }
            }
            
                if(k-d<0)
                {
                    ans=0;
                    b=0;
                }
                else
                {
                   ans=((k-d)/d)*7;
                   b=k-d-k%d;
                }
               
                for(ll int j=0; j<14; j++)
                {
                    l=j+1;
                    
                    if(v1[i+j]==1)
                    {
                        b++;
                        // cout<<b<<" ";
                        if(b==k)
                        {
                            break;
                        }
                    }
        
                    
                }
                ans=ans+l;
            //  cout<<ans<<l<<endl;
            
            ans1=min(ans1,ans);
        }
        
        cout<<ans1<<endl;
       
    }
	return 0;
}


Comments

Submit
0 Comments
More Questions

Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix